package com.test.project.system.dajuan.service.impl;

import java.util.List;

import com.test.common.exception.BusinessException;
import com.test.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.test.project.system.dajuan.mapper.TDajuanMapper;
import com.test.project.system.dajuan.domain.TDajuan;
import com.test.project.system.dajuan.service.ITDajuanService;
import com.test.common.utils.security.ShiroUtils;
import com.test.common.utils.text.Convert;

/**
 * 用户问卷Service业务层处理
 * 
 * @author test
 * @date 2023-12-05
 */
@Service
public class TDajuanServiceImpl implements ITDajuanService 
{
    @Autowired
    private TDajuanMapper tDajuanMapper;

    /**
     * 查询用户问卷
     * 
     * @param id 用户问卷ID
     * @return 用户问卷
     */
    @Override
    public TDajuan selectTDajuanById(Long id)
    {
        return tDajuanMapper.selectTDajuanById(id);
    }

    /**
     * 查询用户问卷列表
     * 
     * @param tDajuan 用户问卷
     * @return 用户问卷
     */
    @Override
    public List<TDajuan> selectTDajuanList(TDajuan tDajuan)
    {
        return tDajuanMapper.selectTDajuanList(tDajuan);
    }

    /**
     * 新增用户问卷
     * 
     * @param tDajuan 用户问卷
     * @return 结果
     */
    @Override
    public int insertTDajuan(TDajuan tDajuan)
    {
        
        
        
    	tDajuan.setCreateBy(ShiroUtils.getLoginName());
    	List<TDajuan> olds = tDajuanMapper.selectTDajuanList(tDajuan);
    	if(olds.size()>0) {
    		throw new BusinessException("不能重复提交！");
    	}
    	tDajuan.setStatus("0");
        //tDajuan.setCreateTime(DateUtils.getNowDate());
        
        
        return tDajuanMapper.insertTDajuan(tDajuan);
    }

    /**
     * 修改用户问卷
     * 
     * @param tDajuan 用户问卷
     * @return 结果
     */
    @Override
    public int updateTDajuan(TDajuan tDajuan)
    {
        return tDajuanMapper.updateTDajuan(tDajuan);
    }

    /**
     * 删除用户问卷对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTDajuanByIds(String ids)
    {
        return tDajuanMapper.deleteTDajuanByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除用户问卷信息
     * 
     * @param id 用户问卷ID
     * @return 结果
     */
    @Override
    public int deleteTDajuanById(Long id)
    {
        return tDajuanMapper.deleteTDajuanById(id);
    }
}
